/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dio.com.dao.conexao;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author DiÃ³genes
 */
public class AcessoGED {

    Connection con;
    String nome = "root";
    //Senha contabli
    //String password = "anakin2010";
    String password = "123456";
    PreparedStatement pstm;
    Statement statement;
    public ResultSet rs;

    public static void main(String args[]) {
        new AcessoGED();
    }

    public AcessoGED() {
        conectar();
    }

    public Connection conectar() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //Servidor JP
            //con = DriverManager.getConnection("jdbc:mysql://192.168.0.1:3306/ged-leal_2.0?user=" + nome + "&password=" + password);
            //Marizete
            //con = DriverManager.getConnection("jdbc:mysql://10.1.1.2/ged-leal_2.0?ser=" + nome + "&password=" + password);
            //Contabli
            //con = DriverManager.getConnection("jdbc:mysql://192.168.0.243:3306/ged-contabli?user=" + nome + "&password=" + password);
            con = DriverManager.getConnection("jdbc:mysql://localhost/ged-contabli?user=" + nome + "&password=" + password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.getMessage(), "Erro! Driver não encontrado", JOptionPane.ERROR_MESSAGE);
        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
        }
        return con;
    }

    public void desconectar() {
        try {
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void executeSQL(String sql) {
        try {
            statement = con.createStatement(
                    ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            rs = statement.executeQuery(sql);
        } catch (SQLException sqlex) {
            JOptionPane.showMessageDialog(null, "Não foi possível "
                    + "executar o comando sql," + sqlex + ", o sql passado foi " + sql);
        }

    }
}
